home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
archiver
/
ltarv3.zip
/
LOCATE.C
< prev
next >
Wrap
C/C++ Source or Header
|
1991-09-09
|
2KB
|
113 lines
#include <conio.h>
#include <ctype.h>
#include <dos.h>
#include <dir.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define MAXPAT 256
char curDir[MAXPAT], filename[12] ;
char tDrv[3], tDir[MAXPAT], tName[9], tExt[5] ;
char *loc = "*.*", *applyComd ;
int halt = 0 ;
attachTarget( char *loc ) {
int c ;
c = fnsplit( loc, tDrv, tDir, tName, tExt ) ;
if ( c & DRIVE ) {
setdisk( toupper( tDrv[0] ) - 'A' ) ;
if ( getdisk() != toupper( tDrv[0] ) - 'A' )
return 0 ;
}
if ( c & DIRECTORY )
if ( chdir( tDir ) ) {
tDir[strlen( tDir ) - 1] = 0 ;
if ( chdir( tDir ) )
return 0 ;
}
if ( c & FILENAME )
strncpy( filename, tName, 8 ) ;
if ( c & EXTENSION )
strncat( filename, tExt, 4 ) ;
filename[11] = 0 ;
printf( "LOCATE %s\n", filename ) ;
return 1 ;
}
void applyCommand( char *name ) {
static char command[MAXPAT], *ptr ;
if ( applyComd ) {
if ( ( ptr = strstr( applyComd, "$s" ) ) != NULL )
*ptr = '%' ;
sprintf( command, applyComd, name ) ;
puts( command ) ;
system( command ) ;
}
}
char *locatedfile( char *name ) {
static char compTarget[MAXPAT] ;
static char *str ;
loc = getcwd( tDir, MAXPAT ) ;
str = strlen( loc ) == 3 ? "%s%s" : "%s\\%s" ;
sprintf( compTarget, str, loc, name ) ;
return compTarget ;
}
void recusiveSearch( void ) {
static struct ffblk tag ;
struct ffblk dir ;
int c ;
for ( c = findfirst( "*.*", &dir, FA_DIREC | FA_RDONLY | FA_ARCH ) ;
!c ; c = findnext( &dir ) ) {
if ( halt )
break ;
if ( dir.ff_attrib & FA_DIREC ) {
loc = dir.ff_name ;
if ( *loc != '.' ) {
chdir( loc ) ;
recusiveSearch() ;
}
}
}
for ( c = findfirst( filename, &tag, FA_DIREC | FA_RDONLY | FA_ARCH ) ;
!c ; c = findnext( &tag ) ) {
if ( kbhit() )
if ( getch() == 27 )
halt = 1 ;
if ( halt )
break ;
puts( locatedfile( tag.ff_name ) ) ;
applyCommand( tag.ff_name ) ;
}
chdir( ".." ) ;
}
main( int argc, char *argv[] ) {
if ( argc > 1 )
loc = argv[1] ;
if ( argc > 2 )
applyComd = argv[2] ;
getcwd( curDir, MAXPAT ) ;
if ( attachTarget( loc ) )
recusiveSearch() ;
setdisk( curDir[0] - 'A' ) ;
chdir( curDir ) ;
}